function RequestRecentDiscussions() {
    var prefs = new gadgets.Prefs();
    var feed_url = prefs.getString("feed");
    var params = {};
    params[gadgets.io.RequestParameters.CONTENT_TYPE] =
	gadgets.io.ContentType.DOM;
    params[gadgets.io.RequestParameters.REFRESH_INTERVAL] = 0;
    gadgets.io.makeRequest(feed_url, ProcessDiscussions, params);
}

function ProcessDiscussions(obj) {
    var html = "";
    var now = new Date();
    var rss = obj.data.documentElement;
    var channel = XMLChildrenByNodeName(rss, 'channel')[0];
    var posts = XMLChildrenByNodeName(channel, 'item');
    if (posts.length > 3) posts.length = 3;
    for (var i = 0; i < posts.length; ++i) {
	var post = posts[i];
	var author = XMLChildrenByNodeName(post, 'author')[0].textContent;
	author = author.substr(author.indexOf('(') + 1);
	author = author.substr(0, author.length - 4)
	var timestamp = new Date(XMLChildrenByNodeName(post, 'pubDate')[0].textContent);
	var title = XMLChildrenByNodeName(post, 'title')[0].textContent;
	var snippet = XMLChildrenByNodeName(post, 'description')[0].textContent;
	if (snippet.length > 200) snippet = snippet.substr(0, 200) + '...';
	var verb = "said";
	if (title.substr(0, 4) == "Re: " ||
	    title.substr(0, 4) == "re: ") {
	    verb = "replied";
	    title = title.substr(4);
	}
	var image_url = CalculateBackendURL("/gadgets/nophoto.png");
	var link = CalculateSiteURL('/discussions');
	html += '<div class="article"><h4><a href="' + link +
	    '" target="_top">' +  title +
	    '</a></h4><p><img src="' + image_url +
	    '" class="avatar"> <span class="author">' + author +
	    '</span> ' + verb + ' <span class="time" pubdate> (' + TextifyAge(now, timestamp) +
	    ')</span></p><p>' + snippet +
	    '</p></div>';
    }
    html += '<p><a href="' + CalculateSiteURL("/discussions") +
	'" class="jump" target="_top">More discussions</a></p>';
    document.getElementById('post_list').innerHTML = html;
    gadgets.window.adjustHeight();
}
